<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: 华哥
  Date: 2021/5/12
  Time: 9:22
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <%
        //获取项目的根路径
        String path = request.getContextPath();
        String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
    %>
    <meta charset="utf-8">
    <title>湖南省长沙市华子医院</title>
    <link rel="stylesheet" type="text/css" href="<%=basePath%>static/swee/sweetalert.css">
    <script type="text/javascript" src="<%=basePath%>static/swee/sweetalert-dev.js"></script>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="<%=basePath%>static/layui-v2.6.5/layui/css/layui.css" media="all">

    <style type="text/css">

        .span {
            display: inline-block;
            width: 100px;
            height: 30px;
            text-align: center;
            line-height: 30px;
        }

        .liui {
            border: 1px transparent solid;
            background-color: transparent;
        }

        .biaodan {
            margin-top: 50px;
            text-align: center;
        }

        .biaodan input[type="text"] {
            width: 150px;
            height: 25px;
        }

        #selectStatus {
            margin-left: 100px;
        }

        .box-details {
            width: 350px;
            height: 300px;
            background: #009688;
            position: absolute;
            top: 250px;
            right: 550px;
            z-index: 10;
        }

        .span2 {
            display: inline-block;
            width: 80px;
            text-align: center;
            color: white;
        }

        .box-details ul {
            margin-top: 10px;
        }

        .exit {
            position: absolute;
            top: 250px;
            right: 140px;
        }
    </style>
    <link rel="shortcut icon" href="#"/>
</head>
<body>
<form action="<%=basePath%>FySelect" method="post" class="biaodan">
    <p> 申请人：<input type="text" name="name">
        &nbsp;&nbsp;&nbsp;药&nbsp;&nbsp;&nbsp;名：
        <input type="text" name="yaoName">
        &nbsp;&nbsp;&nbsp;<input type="submit" value="查询" class="layui-btn layui-btn-radius">
        <a href="<%=basePath%>FySelect?applyStatus=1" id="selectStatus"
           class="layui-btn layui-btn-radius">
            查询已同意
        </a>
    </p>
</form>
<table class="layui-table" lay-even="" lay-skin="nob">
    <colgroup>
        <col width="150">
        <col width="150">
        <col width="200">
        <col>
    </colgroup>
    <thead>
    <tr>
        <th>编号</th>
        <th>申请人</th>
        <th>申请时间</th>
        <th>药总类</th>
        <th>药名</th>
        <th>药类型</th>
        <th>单价</th>
        <th>数量</th>
        <th>申请类型</th>
        <th>处理类型</th>
        <th>备注</th>
        <th>操作</th>
    </tr>
    </thead>
    <tbody>
    <c:forEach items="${page.list}" var="list">
        <tr>
            <td>${list.id}</td>
            <td>${list.applycat}</td>
            <td>${list.applytime}</td>
            <td>${list.drugspecies}</td>
            <td>${list.applydrug}</td>
            <td>${list.drugtype}</td>
            <td>${list.price}</td>
            <td>${list.count}</td>
            <td>${list.type}</td>
            <td id="color">${list.statu}</td>
            <td>${list.remark}</td>
            <td>
                <c:if test="${list.applystatus==0}">
                    <a href="javascript:void(0)" onclick="consents(${list.id})" class="layui-btn layui-btn-sm">同意</a>
                </c:if>
                <c:if test="${list.applystatus!=0}">
                    <button class="layui-btn layui-btn-sm" readonly>已批准</button>
                </c:if>
                <a href="javascript:void(0)" class="layui-btn layui-btn-sm detas">详情</a>
            </td>
        </tr>
    </c:forEach>
    </tbody>
</table>
<div class="box-details" hidden>
    <table class="layui-table" lay-skin="line">
        <thead>
        <tr>
            <th>编号</th>
            <th>药名</th>
            <th>单价</th>
            <th>数量</th>
        </tr>
        </thead>
        <tbody id="he">
        </tbody>
    </table>
    <button type="button" class="layui-btn layui-btn-normal exit">关闭</button>
</div>

<p style="text-align: center">
    <a href="<%=basePath%>FySelect?pageNum=${page.prePage}"
       class="layui-btn layui-btn-primary layui-border-blue">上一页</a>
    ${page.pageNum}/${page.pages}
    <a href="<%=basePath%>FySelect?pageNum=${page.nextPage}"
       class="layui-btn layui-btn-primary layui-border-blue">下一页</a>
</p>

<script type="text/javascript" src="<%=basePath%>static/jquery/jquery-1.12.4.js"></script>
<script src="<%=basePath%>static/layui-v2.6.5/layui/layui.js" charset="utf-8"></script>

<script type="text/javascript">
    $(function () {

        $(".exit").click(function () {
            $(".box-details").hide();
        })

        $(".detas").click(function () {

            let time = $(this).parent().parent().children("td:eq(2)").text();
            let type = $(this).parent().parent().children("td:eq(8)").text();

            if (type == "新增药品") {
                return;
            }

            $.ajax({
                url: "<%=basePath%>details",
                type: "post",
                data: {
                    time: time
                },
                dataType: "json",
                success: function (data) {
                    let lis = ``;
                    $.each(data, function (index, val) {
                        lis += `<li class="liui">
                                   <span class="span">\${val.id}</span>
                                   <span class="span">\${val.drugName}</span>
                                   <span class="span">\${val.price}</span>
                                   <span class="span">\${val.count}</span>
                                </li>`;
                    });

                    let show = `<div>
                                   <ul>
                                      <li class="liui">
                                         <span class="span">药品编号</span>
                                         <span class="span">药品名称</span>
                                         <span class="span">药品价格</span>
                                         <span class="span">药品数量</span>
                                      </li>
                                      \${lis}
                                   </ul>
                                </div>`;

                    swal({
                        title: "申请药品详情",    //标题
                        text: show,         //测试
                        allowEscapeKey: true,  //ESC退出
                        confirmButtonText: "关闭",    //确定按钮文字描叙
                        html: true,
                    });

                }
            });
        })
    })

    function consents(id) {
        swal({
                title: "确定同意申请吗？",
                text: "你将无法恢复该虚拟文件！",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "确定同意！",
                cancelButtonText: "取消同意！",
                closeOnConfirm: false,
                closeOnCancel: false
            },
            function (isConfirm) {
                console.log(isConfirm + "点击确定" + id)
                if (isConfirm) {
                    $.ajax(
                        {
                            url: "<%=basePath%>consent",
                            type: "post",
                            data: {
                                id: id
                            },
                            dataType: "json",
                            success: function (data) {
                                swal({
                                    title: "审核通过"
                                }, function () {
                                    location.reload()
                                })
                            }
                        });

                } else {
                    swal("取消！", "你的虚拟文件是安全的！",
                        "error");
                }
            });
    }


    function del(id) {
        swal({
                title: "确定删除吗？",
                text: "你将无法恢复该虚拟文件！",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "确定删除！",
                cancelButtonText: "取消删除！",
                closeOnConfirm: false,
                closeOnCancel: false
            },
            function (isConfirm) {
                if (isConfirm) {
                    $.ajax({
                        url: "<%=basePath%>delete",
                        data: {
                            id: id
                        },
                        type: "post",
                        dataType: "json",
                        success: function (data) {
                            swal("删除成功！", "你的虚拟文件已经被删除。",
                                "success");
                            location.reload();
                        }
                    });
                } else {
                    swal("取消！", "你的虚拟文件是安全的:)",
                        "error");
                }
            });
    }

</script>
</body>
</html>
